//
// Created by wangliewei on 2021/8/17.
//

/*j表示往左最远能到什么地方
此方法空间消耗太大；
可以动态规划
*/

#include<iostream>
using namespace std;

const int N = 100010;
int a[N], s[N];

int main () {

    int n;
    cin >> n;
    for (int i = 0; i < n ; i ++) scanf("%d", &a[i]);
    int res = 0;
    for (int i = 0, j = 0; i < n; i++) {
        s[a[i]]++;
        while (s[a[i]] > 1) {
            s[a[j]]--;
            j ++;
        }
        res = max(res, i - j + 1);
    }

    cout << res <<endl;

    return 0;
}

